﻿using System;
using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class HobbyGuidLookupController : LookupController
    {
        private readonly IRepo<Hobby> repo;

        public HobbyGuidLookupController(IRepo<Hobby> repo)
        {
            this.repo = repo;
        }

        [HttpPost]
        public ActionResult Search(string search)
        {
            return View(@"Awesome\LookupList", repo.GetAll().Where(o => o.Name.Containz(search)));
        }

        //returns a string that it is going to be shown in the textbox
        public ActionResult Get(Guid? id)
        {
            return Content(id.HasValue ? (repo.GetAll().Where(o => o.IdGuid == id).SingleOrDefault() ?? new Hobby()).Name : "");
        }
    }
}